package com.ljt.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljt.response.Result;
import com.ljt.system.entity.Health;
import com.ljt.system.service.HealthService;
import com.ljt.system.service.HealthVoService;
import com.ljt.system.vo.HealthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/health")
@Api(value = "健康打卡模块", tags = "系统健康打卡接口")
@CrossOrigin
public class HealthController {
    @Autowired
    private HealthService healthService;
    @Autowired
    private HealthVoService healthVoService;

    @ApiOperation(value="健康打卡信息",notes = "查询所有健康打卡信息")
    @GetMapping("/queryHealthCount")
    public Result queryHealthCount(@RequestParam(required = false,defaultValue = "1") Integer current,
                                   @RequestParam(required = false,defaultValue = "2") Integer size){
        Page<HealthVo> healthPage = new Page<>(current, size);
        healthPage = healthVoService.queryHealthCount(healthPage);
        return Result.ok().data("healthPage",healthPage);
    }

    @ApiOperation(value="添加健康打卡信息",notes = "添加健康打卡信息")
    @GetMapping("/saveHealth")
    public Result saveHealth(Health health){
        boolean i=healthService.save(health);
        if(i){
            return Result.ok().data("health",health);
        }else{
            return Result.error();
        }

    }

    @ApiOperation(value="删除健康打卡信息",notes = "删除健康打卡信息")
    @GetMapping("/deleteHealth")
    public Result deleteHealth(Integer id){
        boolean i=healthService.removeById(id);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }

    }

    @ApiOperation(value="修改健康打卡信息",notes = "修改健康打卡信息")
    @GetMapping("/updateHealth")
    public Result updateHealth(Health health){
        boolean i=healthService.updateById(health);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }

    }


}
